﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                    xmlns:vtv="http://schemas.rapidapplicationservices.com/vtv/virtualizedtreeview/">

    <DataTemplate x:Key="ItemTemplate">
        <TextBlock Text="{Binding BoundItem}"></TextBlock>
    </DataTemplate>

    <DataTemplate x:Key="ExpandedItemTemplate">
        <TextBlock Text="{Binding BoundItem}">
          
        </TextBlock>
    </DataTemplate>

    <ItemsPanelTemplate x:Key="PanelTemplate">
        <VirtualizingStackPanel/>
    </ItemsPanelTemplate>

    <ControlTemplate TargetType="vtv:VirtualizingTree" x:Key="ControlTemplate">
        <ScrollViewer BorderThickness="{TemplateBinding BorderThickness}"
                      BorderBrush="{TemplateBinding BorderBrush}"
                      Background="{TemplateBinding Background}">
            <ItemsPresenter />
        </ScrollViewer>
    </ControlTemplate>

    <ControlTemplate TargetType="vtv:VirtualizingTreeItem" x:Key="MultiSelectTreeItemTemplate">
        <Grid>
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal" />
                    <VisualState x:Name="MouseOver">
                    </VisualState>
                    <VisualState x:Name="Disabled">
                    </VisualState>
                </VisualStateGroup>
                <VisualStateGroup x:Name="SelectionStates">
                    <VisualState x:Name="Unselected">
                    </VisualState>
                    <VisualState x:Name="Selected">
                    </VisualState>
                </VisualStateGroup>
                <VisualStateGroup x:Name="FocusStates">
                    <VisualState x:Name="Focused">
                    </VisualState>
                    <VisualState x:Name="Unfocused"/>
                </VisualStateGroup>
                <VisualStateGroup x:Name="ArrowStates">
                    <VisualState x:Name="ArrowMouseOver">
                        <Storyboard>
                            <ColorAnimation Duration="0" Storyboard.TargetName="Arrow" Storyboard.TargetProperty="(Polygon.Fill).(SolidColorBrush.Color)" To="White"/>
                            <ColorAnimation Duration="0" Storyboard.TargetName="Arrow" Storyboard.TargetProperty="(Polygon.Stroke).(SolidColorBrush.Color)" To="#B90E92CA"/>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="ArrowNormal">
                    </VisualState>
                </VisualStateGroup>
                <VisualStateGroup x:Name="ExpanderStates">
                    <VisualState x:Name="Expanded">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ExpandedContentPresenter" 
                                                           Storyboard.TargetProperty="Visibility">
                                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
                            </ObjectAnimationUsingKeyFrames>
                            <DoubleAnimation Storyboard.TargetName="expanderRotateTransform" 
                                                 Storyboard.TargetProperty="Angle"
                                                 FillBehavior="HoldEnd"
                                                 To="45"
                                                 Duration="0:0:0.2"/>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Collapsed">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CollapsedContentPresenter" 
                                                           Storyboard.TargetProperty="Visibility">
                                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
                            </ObjectAnimationUsingKeyFrames>
                            <DoubleAnimation Storyboard.TargetName="expanderRotateTransform" 
                                                 Storyboard.TargetProperty="Angle"
                                                 FillBehavior="HoldEnd"
                                                 To="0"
                                                 Duration="0:0:0.2"/>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="14"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Border x:Name="Expander" 
                    Visibility="{TemplateBinding ExpanderVisibility}"
                    Background="Transparent" 
                    IsHitTestVisible="True" 
                    Grid.Column="0">
                <Polygon x:Name="Arrow" Points="0,0 4,4 0,8" Fill="Black" 
                         Stroke="Transparent" StrokeThickness="0.5"  Margin="5" RenderTransformOrigin="0.5,0.5" 
                             VerticalAlignment="Center"
                             HorizontalAlignment="Center">
                    <Polygon.RenderTransform>
                        <RotateTransform x:Name="expanderRotateTransform"></RotateTransform>
                    </Polygon.RenderTransform>
                </Polygon>
            </Border>
            <StackPanel Orientation="Horizontal" Grid.Column="1"  Margin="{TemplateBinding Padding}">
                <CheckBox x:Name="ToggleButton" IsThreeState="False">
                </CheckBox>
                <ContentPresenter x:Name="CollapsedContentPresenter"
                              Visibility="Collapsed"
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                              ContentTemplate="{TemplateBinding ContentTemplate}"
                              Content="{TemplateBinding Content}"
                              Margin="5,0,0,0"/>
                <ContentPresenter x:Name="ExpandedContentPresenter"
                              Visibility="Collapsed"
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                              ContentTemplate="{TemplateBinding ExpandedContentTemplate}"
                              Content="{TemplateBinding Content}"
                              Margin="5,0,0,0"/>
            </StackPanel>
        </Grid>
    </ControlTemplate>

    <Style TargetType="vtv:VirtualizingTreeItem" x:Key="MultiSelectItemStyle">
        <Setter Property="Template" Value="{StaticResource MultiSelectTreeItemTemplate}"/>
    </Style>

    <Style TargetType="vtv:VirtualizingTree">
        <Setter Property="Indent" Value="22.5"/>
        <Setter Property="ItemsPanel" Value="{StaticResource PanelTemplate}"/>
        <Setter Property="Template" Value="{StaticResource ControlTemplate}"/>
        <Setter Property="ItemTemplate" Value="{StaticResource ItemTemplate}"/>
        <Setter Property="ExpandedItemTemplate" Value="{StaticResource ExpandedItemTemplate}"/>
        <Setter Property="MultiSelectItemStyle" Value="{StaticResource MultiSelectItemStyle}"/>
    </Style>

</ResourceDictionary>
